﻿Imports System
Imports System.IO
Imports System.Data
Imports System.Data.SqlServerCe
Imports System.Drawing
Imports System.Collections
Imports System.Windows.Forms
Imports System.Data.Common

Module SystemTypeDao

    Public Function findSystemTypes(ByVal projectId As String, ByVal systemName As String) As DataTable
        Dim dtResult As New DataTable
        Dim paramList As New Hashtable()

        Dim SQL As String = "SELECT * FROM eqam_system_type WHERE 1=1 "

        If (projectId IsNot Nothing And projectId <> "") Then
            SQL = SQL & " AND PROJECT_ID = @PROJECT_ID"
            paramList.Add("@PROJECT_ID", projectId)
        End If

        If (systemName IsNot Nothing And systemName <> "") Then
            SQL = SQL & " AND SYSTEM_TYPE_NAME = @SYSTEM_TYPE_NAME"
            paramList.Add("@SYSTEM_TYPE_NAME", systemName)
        End If

        SQL = SQL & " ORDER BY SYSTEM_TYPE_NAME "

        Return LoadData(SQL, paramList)
    End Function

    Public Function fetchDrawingNumberBySystem(ByVal projectId As String, ByVal systemType As String) As String
        Dim dtResult As New DataTable
        Dim paramList As New Hashtable()
        Dim result As String = ""

        Dim SQL As String = "SELECT * FROM eqam_system_type WHERE PROJECT_ID = @PROJECT_ID AND SYSTEM_TYPE_NAME = @SYSTEM_TYPE_NAME"

        paramList.Add("@PROJECT_ID", projectId)
        paramList.Add("@SYSTEM_TYPE_NAME", systemType)

        dtResult = LoadData(SQL, paramList)
        If dtResult.Rows.Count > 0 Then
            result = dtResult.Rows(0).Item("DRAWING_NUMBER")
        End If

        Return result
    End Function

    Public Function fetchDrawingNumberBySystemTypeId(ByVal systemTypeId As String) As String
        Dim dtResult As New DataTable
        Dim paramList As New Hashtable()
        Dim result As String = ""

        Dim SQL As String = "SELECT * FROM eqam_system_type WHERE SYSTEM_TYPE_ID = @SYSTEM_TYPE_ID"

        paramList.Add("@SYSTEM_TYPE_ID", systemTypeId)

        dtResult = LoadData(SQL, paramList)
        If dtResult.Rows.Count > 0 Then
            result = dtResult.Rows(0).Item("DRAWING_NUMBER")
        End If

        Return result
    End Function
End Module
